/*
 * Copyright (c) 2018.
 * This file was written by Fancyears·Milos·Malvis @connor. Any question/bug you can't post to 1243093366@qq.com.
 * ALL RIGHTS RESERVED.
 */
package org.fancyears.frame;
/**
* @author: Fancyears·Milos·Malvis
* @CreateDate: 2018年12月4日 下午2:53:30
* @Description:
*/

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.table.*;

public class CFrame extends JFrame {

	private static final long serialVersionUID = 1L;
	private JTable table = null;
	private DefaultTableModel model = null;
	private JScrollPane js = null;

	public CFrame() {
		model = new DefaultTableModel(3, 3);
		table = new JTable(model);
		table.getColumnModel().getColumn(1).setCellEditor(new MyRender());// 设置编辑器
		table.getColumnModel().getColumn(1).setCellRenderer(new MyRender());
		js = new JScrollPane(table);

		this.add(js);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
		this.setSize(399, 300);
		this.setLocationRelativeTo(null);
	}

	public static void main(String[] args) {
// TODO Auto-generated method stub
		new CFrame();
	}

}

//渲染 器 编辑器
class MyRender extends AbstractCellEditor implements TableCellRenderer, ActionListener, TableCellEditor {

	private static final long serialVersionUID = 1L;
	private JButton button = null;

	public MyRender() {
		button = new JButton("确定不？");
		button.addActionListener(this);
	}

	@Override
	public Object getCellEditorValue() {
		return null;
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
			int row, int column) {
		return button;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		JOptionPane.showMessageDialog(null, "渲染器学期", "消息", JOptionPane.OK_OPTION);
	}

	@Override
	public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
		return button;
	}

}
